package mao.exaimnation.zhongxin;

import java.util.Scanner;
//中兴笔试题，字符串转成某进制。进制转换结果相加，看是奇数还是偶数。
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            scanner.nextLine();

            for (int i = 0; i < n; i++) {
                String next = scanner.nextLine();
                String[] split = next.split(" ");
                next = split[0];
                int start = Integer.parseInt(split[1]);
                int end = Integer.parseInt(split[2]);

                char[] chars = next.toCharArray();
                long res = 0;
                for (int j = start; j <= end; j++) {
                    long num = 0;
                    for (int k = 0; k < chars.length; k++) {
                        if (chars[k] <= '9' && chars[k] >= '0') {
                            num = num * j + chars[k] - '0';
                        } else {
                            num = num * j + chars[k] - 'A' + 10;
                        }
                    }
                    res = res + num;
                }
                System.out.println(res & 1);
            }
        }
    }
}
